from common.files.media import MediaFile
from common.template.page import Template
from common.utils.toolkit import Log
from http.server import BaseHTTPRequestHandler
import sys,os,getopt
class Server:

    @staticmethod
    def createHandler(mediadir):
        class RequestHandler(BaseHTTPRequestHandler):
            def do_GET(self):
                self.send_response(200)
                self.send_header("Content-type", "text/html")
                self.end_headers()
                Log.d("access " + self.path)
                if(self.path == "/favicon.ico"):
                    pass
                else:
                    MediaFile().queryMediaFiles(mediadir)
                    map = MediaFile().updateSnapShot()
                    self.wfile.write(Template.createTemplate(map))
                self.wfile.flush()
                # self.wfile.close()
                return
        return RequestHandler
